﻿<link href="~/lib/ztree/ztree.css" rel="stylesheet" asp-append-version="true" />
<script src="~/lib/ztree/ztree.core-3.5.37.min.js" asp-append-version="true"></script>
<script src="~/lib/ztree/ztree.exedit-3.5.37.js" asp-append-version="true"></script>
<script type="text/javascript">
	$(document).ready(function () {
		var treeSetting = {
			view: {
				selectedMulti: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onClick: function (event, treeId, treeNode, clickFlag) {
					var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
					if (parent.@(ViewData["callback"])) {
						parent.@(ViewData["callback"])(treeNode, index);
					} else {
						parent.layer.close(index);
					}
				},
			}
		};
		utils.ajaxPost('@(Url.Action("GetTreeData", "Sys_EnumCode"))', { id: "@(ViewData["id"])",code:"@(ViewData["code"])",orgid:"@(ViewData["orgid"])" }, function (resp) {
			var data = resp.data || [];
			var treeData = [];
			$.each(data, function (idx,item) {
				treeData.push(Object.assign({}, item, {
                    id: item.ID.toString(),
                    pId: item.PID.toString(),
					name: item.Name,
					code: item.Code,
					open: true
				}));
			});
			$.fn.zTree.init($("#@(ViewData["treeid"])"), treeSetting, treeData);
		});
	});
</script>